package rifl.meres4.ui.tracker;

import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTrackerCustomizer;

import rifl.meres4.development.step.IImplementationStep;
import rifl.meres4.ui.WorkflowUI;

public class ImplementationStepServiceTrackerCustomizer implements ServiceTrackerCustomizer<IImplementationStep, Object> {

	private final WorkflowUI ui;
	private final BundleContext context;

	public ImplementationStepServiceTrackerCustomizer(BundleContext context, WorkflowUI ui) {
		this.context = context;
		this.ui = ui;
	}

	@Override
	public Object addingService(ServiceReference<IImplementationStep> reference) {
		IImplementationStep service = context.getService(reference);
		if (ui != null) {
			ui.setImplementationStep(service);
		}
		return service;
	}

	@Override
	public void modifiedService(ServiceReference<IImplementationStep> reference,
			Object service) {
		
	}

	@Override
	public void removedService(ServiceReference<IImplementationStep> reference,
			Object service) {
		if (ui != null) {
			ui.unsetImplementationStep((IImplementationStep) service);
		}
	}
	
}
